package com.ruoyi.web.controller.admin;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.xs.XsOrderRefund;
import com.ruoyi.system.service.IXsOrderRefundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 订单退款信息Controller
 * 
 * @author ruoyi
 * @date 2025-03-06
 */
@RestController
@RequestMapping("/system/order/refund")
public class XsOrderRefundController extends BaseController
{
    @Autowired
    private IXsOrderRefundService xsOrderRefundService;

    /**
     * 查询订单退款信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(XsOrderRefund xsOrderRefund)
    {
        startPage();
        List<XsOrderRefund> list = xsOrderRefundService.selectXsOrderRefundList(xsOrderRefund);
        return getDataTable(list);
    }

    @Log(title = "批量导入数据", businessType = BusinessType.IMPORT)
    @PostMapping(   "/importRefundOrder")
    public AjaxResult importRefundOrder(MultipartFile file) {
        xsOrderRefundService.importRefundOrder(file);
        return success();
    }

    /**
     * 导出订单退款信息列表
     */
    @Log(title = "订单退款信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XsOrderRefund xsOrderRefund)
    {
        List<XsOrderRefund> list = xsOrderRefundService.selectXsOrderRefundList(xsOrderRefund);
        ExcelUtil<XsOrderRefund> util = new ExcelUtil<XsOrderRefund>(XsOrderRefund.class);
        util.exportExcel(response, list, "订单退款信息数据");
    }

    /**
     * 获取订单退款信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(xsOrderRefundService.selectXsOrderRefundById(id));
    }

    /**
     * 新增订单退款信息
     */
    @Log(title = "订单退款信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XsOrderRefund xsOrderRefund)
    {
        return toAjax(xsOrderRefundService.insertXsOrderRefund(xsOrderRefund));
    }

    /**
     * 修改订单退款信息
     */
    @Log(title = "订单退款信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XsOrderRefund xsOrderRefund)
    {
        return toAjax(xsOrderRefundService.updateXsOrderRefund(xsOrderRefund));
    }

    /**
     * 删除订单退款信息
     */
    @Log(title = "订单退款信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(xsOrderRefundService.deleteXsOrderRefundByIds(ids));
    }
}
